﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "PaperZDAnimInstance.h"
#include "PaperZDCharacter.h"
#include "GameFramework/Actor.h"
#include "DefenceTower.generated.h"

UCLASS()
class TAFANG2_API ADefenceTower : public APaperZDCharacter
{
	GENERATED_BODY()
	
	UPROPERTY(VisibleAnywhere, Category="Tower", meta=(AllowPrivateAccess=true))
	class USphereComponent* SphereComponent;

	UPROPERTY(EditAnywhere, Category="Tower",meta=(AllowPrivateAccess=true))
	UPaperZDAnimSequence* AttackSequence;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Tower",meta=(AllowPrivateAccess=true))
	bool IsAttack = false;
	
	// 攻击范围
	float AttackRadius = 500.0f;
	// 攻击频率
	float AttackInterval = 2.0f;
	// 攻击计时器
	float AttackTimer = 0.0f;



	// 攻击范围内的敌人
	TArray<class AEnemyZDCharacter*> EnemiesList;
	
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess=true))
	AEnemyZDCharacter* AttackTarget;

	FZDOnAnimationOverrideEndSignature OnAttackOverrideEndDelegate;


public:
	ADefenceTower();
	virtual void BeginPlay() override;
	virtual void Tick(float DeltaTime) override;

	UFUNCTION()
	void OnComponentBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

	UFUNCTION()
	void OnComponentEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
	
	void Attack();
	void FindEnemyInRadius();
	bool InRange(AEnemyZDCharacter* Target);

	UFUNCTION()
	void OnAttackOverrideEnd( bool bCompleted);
	
};

